﻿namespace Huayou.UI.WebControls
{
    using System;
    using System.Web.UI;
    using System.Xml;

    internal class MenuItemDefault : MenuItemRenderBase
    {
        public MenuItemDefault(XmlElement node, MenuGroup parentGroup, WebMenu menu) : base(node, parentGroup, menu)
        {
        }

        public override void RenderCssItem(HtmlTextWriter output)
        {
            output.AddAttribute("class", base.CssClass);
            if (base.Width != null)
            {
                output.AddAttribute("width", base.Width.ToString());
            }
            if (base.Height != null)
            {
                output.AddAttribute("height", base.Height.ToString());
            }
            if (base.ClientSideID != null)
            {
                output.AddAttribute("id", base.ClientSideID);
            }
            output.RenderBeginTag("td");
            if (base.URL != null)
            {
                output.AddAttribute("href", base.URL);
                if (base.URLTarget != null)
                {
                    output.AddAttribute("target", base.URLTarget);
                }
                output.RenderBeginTag("a");
                output.AddAttribute("class", base.CssClass);
                output.RenderBeginTag("font");
            }
            output.Write(base.Label);
            if (base.URL != null)
            {
                output.RenderEndTag();
                output.RenderEndTag();
            }
            output.RenderEndTag();
        }

        public override void RenderIconItem(HtmlTextWriter output)
        {
            if (base.Width != null)
            {
                output.AddAttribute("width", base.Width.ToString());
            }
            if (base.Height != null)
            {
                output.AddAttribute("height", base.Height.ToString());
            }
            output.RenderBeginTag("td");
            if (base.CssClass != null)
            {
                output.AddAttribute("class", base.CssClass);
            }
            output.AddAttribute("id", base.ClientSideID);
            output.AddAttribute("cellpadding", "0");
            output.AddAttribute("cellspacing", "0");
            output.AddAttribute("border", "0");
            output.AddAttribute("width", "100%");
            output.AddAttribute("height", "100%");
            output.RenderBeginTag("table");
            output.RenderBeginTag("tr");
            if (base.LeftIcon != null)
            {
                output.Write(string.Concat(new object[] { "<td style=\"padding:0;\" width=", base.ParentGroup.MaxLeftIconWidth, "><img src=\"", base.LeftIcon, "\" border=0></td>" }));
            }
            else if (base.ParentGroup.MaxLeftIconWidth != 0)
            {
                output.Write("<td style=\"padding:0;\" width=" + base.ParentGroup.MaxLeftIconWidth + "></td>");
            }
            if (base.Image != null)
            {
                this.RenderImageItem(output);
            }
            else
            {
                this.RenderCssItem(output);
            }
            if (base.RightIcon != null)
            {
                output.Write(string.Concat(new object[] { "<td align=right style=\"padding:0;\" width=", base.ParentGroup.MaxRightIconWidth, "><img src=\"", base.RightIcon, "\" border=0></td>" }));
            }
            else if (base.ParentGroup.MaxRightIconWidth != 0)
            {
                output.Write("<td align=right style=\"padding:0;\" width=" + base.ParentGroup.MaxRightIconWidth + "></td>");
            }
            output.RenderEndTag();
            output.RenderEndTag();
            output.RenderEndTag();
        }

        public override void RenderImageItem(HtmlTextWriter output)
        {
            string str = "<td";
            if (base.Width != null)
            {
                str = str + " width=" + base.Width.ToString();
            }
            if (base.Height != null)
            {
                str = str + " height=" + base.Height.ToString();
            }
            if (base.ClientSideID != null)
            {
                str = str + " id=" + base.ClientSideID;
            }
            str = str + ">";
            if (base.URL != null)
            {
                str = str + "<a href=\"" + base.URL + "\"";
                if (base.URLTarget != null)
                {
                    str = str + " target=" + base.URLTarget;
                }
                str = str + ">";
            }
            str = str + "<img src=\"" + base.Image + "\" border=0";
            if (base.Width != null)
            {
                str = str + " width=" + base.Width.ToString();
            }
            if (base.Height != null)
            {
                str = str + " height=" + base.Height.ToString();
            }
            if (base.CssClass != null)
            {
                str = str + " class=" + base.CssClass;
            }
            str = str + ">";
            if (base.URL != null)
            {
                str = str + "</a>";
            }
            str = str + "</td>";
            output.Write(str);
        }
    }
}

